package com.huifer.wgx.service.impl;

import com.huifer.wgx.model.ResultLineAttrEntity;
import com.huifer.wgx.repository.ResultLineAttrRepository;
import com.huifer.wgx.service.ResultLineAttrService;
import org.omg.CORBA.PRIVATE_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

/**
 * <p>Title : ResultLineAttrServiceImpl </p>
 * <p>Description : </p>
 *
 * @author huifer
 * @date 2019-03-22
 */
@Service
public class ResultLineAttrServiceImpl implements ResultLineAttrService {

    @Autowired
    private ResultLineAttrRepository lineAttrRepository;

    /**
     * 保存线段额外属性
     *
     * @param resultLineAttrEntity 线段额外属性
     * @return 线段额外属性
     */
    @Override
    public ResultLineAttrEntity save(ResultLineAttrEntity resultLineAttrEntity) {

        try {
            return lineAttrRepository.save(resultLineAttrEntity);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 查询所有
     *
     * @param pageNum 页面号
     * @param pageSize 页面大小
     * @return 线段额外属性
     */
    @Override
    public Page<ResultLineAttrEntity> findAll(Integer pageNum, Integer pageSize) {
        Sort sort = new Sort(Direction.DESC, "otherLineAttrId");
        Pageable pageable = PageRequest.of(pageNum - 1, pageSize, sort);
        return lineAttrRepository.findAll( pageable);
    }
}
